package cn.gov.service.impl;

import cn.geracomium.util.service.abs.AbstractService;
import cn.gov.dao.IMemberBaseDAO;
import cn.gov.service.IMemberBaseService;
import cn.gov.vo.MemberBase;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Service
public class MemberBaseServiceImpl extends AbstractService implements IMemberBaseService {
    @Autowired
    private IMemberBaseDAO memberBaseDAO;
    @Override
    public Map<String, Object> list(Long currentPage,Integer lineSize,String column,String keyWord) {
        Map<String,Object> result = new HashMap<>() ;
        Map<Long,Object> ages = new HashMap<>();
        Map<String,Object> paramMap = super.paramConverterMap(currentPage, lineSize, column, keyWord) ;
        result.put("allMembers", this.memberBaseDAO.findSplit(paramMap)) ;
        result.put("allRecorders", this.memberBaseDAO.getAllCount(paramMap)) ;
        for (Object object:this.memberBaseDAO.findSplit(paramMap)) {
            Date currentTime = new Date();
            Date birthday = ((MemberBase) object).getBirthday();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
            int age = Integer.parseInt(formatter.format(currentTime))-Integer.parseInt(formatter.format(birthday));
            ages.put(((MemberBase) object).getMemberId(),age);
        }
        result.put("allAges",ages);
        return result;
    }

    @Override
    public MemberBase get(Long memberId) {
        return this.memberBaseDAO.findById(memberId);
    }

    @Override
    public boolean edit(MemberBase memberBase) {
        return this.memberBaseDAO.doEdit(memberBase);
    }

    @Override
    public MemberBase findName(String name) {
        return null;
    }

    @Override
    public MemberBase findPid(int pid) {
        return null;
    }

    @Override
    public MemberBase findPNid(int pnid) {
        return null;
    }

    @Override
    public Map<String, Object> listAll(long currentPage, int lineSize, String column, String keyWord) {
        return null;
    }
}
